package com.home.simple.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.home.simple.model.Reservation;
import com.home.simple.service.ReservationService;

@Controller
@RequestMapping("/reservationQuery")
public class ReservationController {
	
	@Autowired
	private ReservationService reservationService;
	

	@RequestMapping(method = RequestMethod.GET)
	public String displayForm(){
		return "reservationQuery";
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public String submitForm(@RequestParam("courtName") String courtName, Model model){
		
		List<Reservation> reservations = reservationService.getReservations(courtName);
		model.addAttribute("reservations", reservations);
		return "reservationQuery";
	}
}
